package com.gdk.ksoft.ui.works.adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gdk.ksoft.R;
import com.gdk.ksoft.ui.works.models.SaleTypeModel;

import java.util.List;

/**
 * Created by hel on 2014-12-25.
 * 促销类型数据适配器
 */
public class PsaleTypeAdapter extends BaseAdapter {

    private Context context;
    private List<SaleTypeModel> typelist;

    public PsaleTypeAdapter(Context context,List<SaleTypeModel> typelist){
        this.context = context;
        this.typelist = typelist;
    }

    @Override
    public int getCount() {
        return typelist == null?0:typelist.size();
    }

    @Override
    public Object getItem(int position) {
        return typelist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final SaleTypeModel item = typelist.get(position);
        View rootView = View.inflate(context, R.layout.item_pplaceorder_listsaletype,null);
        TextView txtType = (TextView)rootView.findViewById(R.id.item_pplaceorder_listsaletype_txtContent);
        txtType.setText(item.typeName);
        Drawable iconLeft = null,iconRight = null;//左边的图标与右边的图标
        if(item.resId!=0){
            iconLeft = context.getResources().getDrawable(item.resId);
            iconLeft.setBounds(0,0,iconLeft.getIntrinsicWidth(),iconLeft.getIntrinsicHeight());
        }
        iconRight = context.getResources().getDrawable(R.drawable.ic_arrow_right);
        iconRight.setBounds(0,0,iconRight.getIntrinsicWidth(),iconRight.getIntrinsicHeight());
        txtType.setCompoundDrawables(iconLeft,null,iconRight,null);
        return rootView;
    }

}
